import { ref } from "vue";
import { nextTick } from "vue";
import { useLocalStorage } from "@vueuse/core";
import { showToast } from "@/utils/toastHelper";
export function useMemoAdd(emit) {

  const memoList = useLocalStorage("memo-list", []);
  const title = ref("");
  const body = ref("");

  async function addMemo() {
    memoList.value = [
      ...memoList.value,
      {
        id: Date.now(),
        title: title.value,
        body: body.value,
      },
    ];
    console.log(localStorage.getItem("memo-list"));
    showToast("添加成功");
    await nextTick(); // 等待 DOM 和响应式更新完成
    emit("backMemoList");
  }
  return {
    title,
    body,
    addMemo,
  }

}
